package com.example.mylibrary.network

import android.os.Parcel
import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import java.io.Serializable

open class BaseData(
    @SerializedName(value = "code", alternate = ["errorCode"])
    var code: Int = 0,

    @SerializedName(value = "status")
    var status: String = "",

    @SerializedName(value = "msg", alternate = ["errorMsg", "message"])
    var msg: String = ""
) : Serializable, Parcelable {
    constructor(parcel: Parcel) : this(
        parcel.readInt(),
        parcel.readString() ?: "",
        parcel.readString() ?: ""
    ) {
    }

    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeInt(code)
        parcel.writeString(status)
        parcel.writeString(msg)
    }

    override fun describeContents(): Int {
        return 0
    }

    companion object CREATOR : Parcelable.Creator<BaseData> {
        override fun createFromParcel(parcel: Parcel): BaseData {
            return BaseData(parcel)
        }

        override fun newArray(size: Int): Array<BaseData?> {
            return arrayOfNulls(size)
        }
    }
}

